// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

// Verify that properties in the base type can be accessed from init


component Foo inherits VerticalLayout {
    in property<string> title: "OK";
    Text {
        text <=> root.title;
    }
}

component Base {
    out property <string> title: "OK";
}

component CompoWithCond  {
    callback dontcrash();
    dontcrash() => {}
    VerticalLayout {
        if (true) : Rectangle {
            init => {
                dontcrash();
            }
        }
    }
}


export component TestCase inherits Rectangle {
    width: 300phx;
    height: 300phx;

    property <bool> ok;
    out property <string> test1: "KO";
    out property <string> test2: "KO";

    in property <bool> cond: false;

    if cond: Base {
        init => {
            root.test1 = self.title;
        }
    }

    if cond: Foo {
        init => {
            root.test2 = self.title;
        }
    }

    l := VerticalLayout {
        CompoWithCond {
            dontcrash => {
                root.ok = true;
            }
        }
    }
    out property <bool> test: l.preferred-width == 0px && ok;
}


/*
```rust
let instance = TestCase::new().unwrap();

assert_eq!(instance.get_test1(), "KO");
assert_eq!(instance.get_test2(), "KO");
assert!(instance.get_test());
instance.set_cond(true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq!(instance.get_test1(), "OK");
assert_eq!(instance.get_test2(), "OK");
```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert_eq(instance.get_test1(), "KO");
assert_eq(instance.get_test2(), "KO");
assert(instance.get_test());
instance.set_cond(true);
slint_testing::send_mouse_click(&instance, 5., 5.);
assert_eq(instance.get_test1(), "OK");
assert_eq(instance.get_test2(), "OK");
```


```js
var instance = new slint.TestCase({});
assert.equal(instance.test1, "KO");
assert.equal(instance.test2, "KO");
assert(instance.test);
instance.cond = true;
slintlib.private_api.send_mouse_click(instance, 5., 5.);
assert.equal(instance.test1, "OK");
assert.equal(instance.test2, "OK");
```


*/